package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;

@WebServlet("/TestServlet3")
public class TestServlet3 extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter pw = resp.getWriter();
		
		// 域对象
		
		// application  ServletContext 
		ServletContext sc = req.getServletContext();
		// session 		HttpSession
		HttpSession session = req.getSession();
		// pageContext 上下文
		//PageContext pageContext = getServletContext() 
		
		
		req.setAttribute("name", "张三 req");
		session.setAttribute("name", "李四 session");
		//session.removeAttribute("name");
		sc.setAttribute("name", "王五 application");
		
		req.getRequestDispatcher("/WEB-INF/3域对象.jsp").forward(req, resp);
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}